/*
 * rpmdb.h
 *
 *  Created on: Jan 1, 2010
 *      Author: jkeller
 */
#include <time.h>
#include <stdlib.h>
#include <md5.h>
#include <sys/types.h>
#include <scew/scew.h>
#include "rpm.h"

#ifndef RPMDB_H_
#define RPMDB_H_

#define RPM_DATABASE_NAME ".minirpm_data"

typedef struct RpmDataBase
{
    scew_tree * tree;
    char * root_path;
    char * database_file;
    char * lock_file;
    int writeAccess;
    int dirty;
    int parse_error;

} RpmDataBase;

typedef struct RpmPackage
{
    scew_element * packag_root;
} RpmPackage;

typedef  RpmDataBase* RpmDataBaseHandle;

/*** Package manipulation. */

RpmPackage *
db_addNewPackage( RpmDataBaseHandle db, const char * pkgName );

const RpmPackage *
db_findRpmPackage( RpmDataBaseHandle db, const char * name );

RpmPackage *
db_deletePackage( RpmDataBaseHandle db, RpmPackage * pkg );

/*** Package information */
RpmHeaderElementType
db_getTagType ( RpmDataBaseHandle handle, RpmPackage * pkg, RpmTag theTag, int * count );

char *
db_getTagAsString ( RpmDataBaseHandle handle, RpmPackage * pkg, RpmTag theTag );

char **
db_getTagAsStringArray( RpmDataBaseHandle handle, RpmPackage * pkg, int * numElements );

void
db_freeStringArray( char ** stringArray, int numElements );

RpmPackage *
db_setTag( RpmDataBaseHandle handle, RpmPackage * pkg, RpmTag theTag, RpmHeaderElementType type, const char * value );

RpmPackage *
db_setTagArray( RpmDataBaseHandle    handle,
                RpmPackage *         pkg,
                RpmTag               theTag,
                RpmHeaderElementType type,
                const char * const * value,
                int                  numElements );

RpmDataBaseHandle
db_open( const char * root, int writeAccess, RpmStatus * retVal );

void
db_close( RpmDataBaseHandle db );

#endif /* RPMDB_H_ */
